package y23.Oct;
import java.util.Scanner;

public class Test35 {
    public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int n = in.nextInt();
            while (n > 10) {
                n = num(n);
            }
            System.out.println(n);
        }
    }
    public static int num(int n) {
        int sum = 0;
        while (n > 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}
